﻿@model IFDB.ViewModels.PartialViewModels.PersonAppearancesViewModel

@using (var mainAccordion = Html.JQueryUI().Begin(new Accordion().HeightStyle(HeightStyle.Content).Active(0).Collapsible(true, false)))
{
    foreach (var month in Model.PersonSeasonEventList.GroupBy(m => m.Match.MatchDate.Month))
    {
        using (mainAccordion.BeginPanel(month.Take(1).Single().Match.MatchDate.ToString("MMMM")))
        {
            foreach (var matchGroup in month.GroupBy(m => m.MatchId))
            {
                IFDB.Models.Tables.Match match = matchGroup.Take(1).Single().Match;
                
                <table class="TeamMatchList">
                    
                    <tr class="MatchHeader1">
                        <td colspan="2">
                            @Html.ActionLink(match.Competition.CompetitionName, "Index", "League", new { competitionId = match.Competition.CompetitionId }, null)
                        </td>
                        <td class="Date">
                            @string.Format("{0} {1}", Model.GetDayPrefix(match.MatchDate), match.MatchDate.ToString("MMMM yyyy h:mmtt"))
                        </td>
                    </tr>

                    <tr class="MatchHeader2">
                        <td colspan="2">
                            @Html.DisplayFor(modelItem => match.Venue.VenueName)
                        </td>
                        <td style="text-align: right;">
                            @foreach(var appearanceEvent in matchGroup)
                            {
                                @Html.Partial("~/Views/Shared/Match/_AppearanceImages.cshtml", appearanceEvent )
                            }
                        </td>
                    </tr>

                    <tr>
                        <td class="LeftTeam">
                            @Html.ActionLink(match.Team1.TeamName, "Index", "Team", new { teamId = match.Team1.TeamId }, null)
                        </td>
                        <td class="Score">
                            @Html.ActionLink(match.Team1FT + " - " + match.Team2FT, "Index", "Match", new { matchId = match.MatchId }, null)
                        </td>
                        <td class="RightTeam">
                            @Html.ActionLink(match.Team2.TeamName, "Index", "Team", new { teamId = match.Team2.TeamId }, null)
                        </td>
                    </tr>
                </table>
            }
        }
    }
}